home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / os2 / pmnos11s / arcnet.c < prev    next >
C/C++ Source or Header  |  1993-07-30  |  2KB  |  125 lines

  1. /* Stuff generic to all ARCnet controllers
  2.  * Copyright 1990 Russ Nelson
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "iface.h"
  8. #include "timer.h"
  9. #include "arp.h"
  10. #include "ip.h"
  11. #include "arcnet.h"
  12.  
  13. char ARC_bdcst[] = { 0 };
  14.  
  15. /* Convert ARCnet header in host form to network mbuf */
  16. struct mbuf *
  17. htonarc(arc,data)
  18. struct arc *arc;
  19. struct mbuf *data;
  20. {
  21.     struct mbuf *bp;
  22.     register char *cp;
  23.  
  24.     if((bp = pushdown(data,ARCLEN)) == NULLBUF)
  25.         return NULLBUF;
  26.  
  27.     cp = bp->data;
  28.  
  29.     memcpy(cp,arc->source,AADDR_LEN);
  30.     cp += AADDR_LEN;
  31.     memcpy(cp,arc->dest,AADDR_LEN);
  32.     cp += AADDR_LEN;
  33.     *cp++ = arc->type;
  34.  
  35.     return bp;
  36. }
  37. /* Extract ARCnet header */
  38. int
  39. ntoharc(arc,bpp)
  40. struct arc *arc;
  41. struct mbuf **bpp;
  42. {
  43.     pullup(bpp,arc->source,AADDR_LEN);
  44.     pullup(bpp,arc->dest,AADDR_LEN);
  45.     arc->type = PULLCHAR(bpp);
  46.     return ARCLEN;
  47. }
  48.  
  49. /* Format an ARCnet address into a printable ascii string */
  50. char *
  51. parc(out,addr)
  52. char *out,*addr;
  53. {
  54.     sprintf(out,"%02x", uchar(addr[0]));
  55.     return  out;
  56. }
  57.  
  58. /* Convert an ARCnet address from Hex/ASCII to binary */
  59. int
  60. garc(out,cp)
  61. register char *out;
  62. register char *cp;
  63. {
  64.     *out = htoi(cp);
  65.     return 0;
  66. }
  67. /* Send an IP datagram on ARCnet */
  68. int
  69. anet_send(bp,iface,gateway,prec,del,tput,rel)
  70. struct mbuf *bp;    /* Buffer to send */
  71. struct iface *iface;    /* Pointer to interface control block */
  72. int32 gateway;        /* IP address of next hop */
  73. int prec;
  74. int del;
  75. int tput;
  76. int rel;
  77. {
  78.     char *agate;
  79.  
  80.     agate = res_arp(iface,ARP_ARCNET,gateway,bp);
  81.     if(agate != NULLCHAR)
  82.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bp);
  83.     return 0;
  84. }
  85. /* Send a packet with ARCnet header */
  86. int
  87. anet_output(struct iface *iface, char *dest, char *source,
  88.             int16 type, struct mbuf *data)
  89. {
  90.     struct arc ap;
  91.     struct mbuf *bp;
  92.  
  93.     memcpy(ap.dest,dest,AADDR_LEN);
  94.     memcpy(ap.source,source,AADDR_LEN);
  95.     ap.type = type;
  96.     if((bp = htonarc(&ap,data)) == NULLBUF){
  97.         free_p(data);
  98.         return -1;
  99.     }
  100.     return (*iface->raw)(iface,bp);
  101. }
  102. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  103. void
  104. aproc(iface,bp)
  105. struct iface *iface;
  106. struct mbuf *bp;
  107. {
  108.     struct arc hdr;
  109.  
  110.     /* Remove ARCnet header and kick packet upstairs */
  111.     ntoharc(&hdr,&bp);
  112.     switch(uchar(hdr.type)){
  113.     case ARC_ARP:
  114.         arp_input(iface,bp);
  115.         break;
  116.     case ARC_IP:
  117.         ip_route(iface,bp,0);
  118.         break;
  119.     default:
  120.         free_p(bp);
  121.         break;
  122.     }
  123. }
  124.  
  125.